#!/bin/bash

# 下载 DomainWordsDict 并解压到 data/res 目录
# 使用方法: ./download-domain-words.sh

GITHUB_URL="https://github.com/liuhuanyong/DomainWordsDict/archive/refs/heads/master.zip"
TARGET_DIR="data/res"
SERVICE_URL="http://localhost:9092/download"

echo "准备下载: $GITHUB_URL"
echo "目标目录: $TARGET_DIR"

# 检查服务是否运行
if ! curl -s -f "$SERVICE_URL" > /dev/null 2>&1; then
    echo "错误: 下载服务未运行 (http://localhost:9092)"
    echo "请先启动服务: cd memento-parent/memento-download && mvn spring-boot:run"
    exit 1
fi

# 调用下载 API
curl -X POST "$SERVICE_URL" \
  -H "Content-Type: application/json" \
  -d "{
    \"urls\": [\"$GITHUB_URL\"],
    \"targetDir\": \"$TARGET_DIR\",
    \"extract\": true
  }" | jq '.'

if [ $? -eq 0 ]; then
    echo ""
    echo "下载完成！文件已保存到: $TARGET_DIR"
else
    echo ""
    echo "下载失败，请检查服务日志"
    exit 1
fi

